package com.example.demo.huawei;

import java.util.Arrays;
import java.util.Scanner;

// 最多可购买的宝石数
/*
7
8
4
6
3
1
6
7
10

 */
public class OD38 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 宝石数
        int n = sc.nextInt();
        if (n == 0) {
            System.out.println(0);
            return;
        }
        // 记录宝石数组
        int[] stones = new int[n];
        for (int i = 0; i < n; i++) {
            stones[i] = sc.nextInt();
        }
        // 拥有的钱
        int v = sc.nextInt();
        System.out.println(Arrays.toString(stones));

        // 求子串问题 一般会采用 双指针

        int i = 0;
        int j = 0;

        int sum = 0;
        int maxLength = 0;
        while (i <= j && j < n) {
            sum = sum + stones[j];
            if (sum < v) {
                maxLength = Integer.max(maxLength, j - i + 1);
                j++;
            } else if (sum == v) {
                maxLength = Integer.max(maxLength, j - i + 1);
                i++;
                j = i;
                sum = 0;
            } else {
                i++;
                j = i;
                sum = 0;
            }
        }
        System.out.println(maxLength);
    }
}
